<!DOCTYPE html>

<html>
<head>
  <title>functions.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="browser.html">
                browser.js
              </a>
            
              
              <a class="source" href="functions.html">
                functions.js
              </a>
            
              
              <a class="source" href="index.html">
                index.js
              </a>
            
              
              <a class="source" href="parser.html">
                parser.js
              </a>
            
              
              <a class="source" href="symtab.html">
                symtab.js
              </a>
            
              
              <a class="source" href="tokenizer.html">
                tokenizer.js
              </a>
            
              
              <a class="source" href="walker.html">
                walker.js
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>functions.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              
            </div>
            
            <div class="content"><div class='highlight'><pre><span class="keyword">var</span> fs = require(<span class="string">'fs'</span>);
<span class="keyword">var</span> path = require(<span class="string">'path'</span>);
<span class="keyword">var</span> slice = [].slice;
<span class="keyword">var</span> tree = require(<span class="string">'./node'</span>);
<span class="keyword">var</span> Color = require(<span class="string">'./helper/color'</span>);



exports.add = <span class="keyword">function</span>(){
    <span class="keyword">return</span> options.args.reduce(<span class="keyword">function</span>(a, b){
        <span class="keyword">return</span> a + b;
    });
}

exports.base64 = <span class="keyword">function</span>(){
    <span class="keyword">var</span> dirname = options.dirname;
    <span class="keyword">if</span>(!fs){
        <span class="keyword">return</span> <span class="string">'url('</span>+options.args[<span class="number">0</span>]+<span class="string">')'</span>
    }<span class="keyword">else</span>{
        
    }
}

exports.u = <span class="keyword">function</span>(string){
    <span class="keyword">if</span>(string.type !== <span class="string">'STRING'</span>){<span class="keyword">throw</span> Error(<span class="string">'mcss function "u" only accept string'</span>)}
    <span class="keyword">return</span> string.val;
}</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap for-h1">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h1>color</h1>

            </div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              
            </div>
            
            <div class="content"><div class='highlight'><pre>exports.lighen = <span class="keyword">function</span>(){

}

exports.darken = <span class="keyword">function</span>(){

}
















<span class="keyword">var</span> mediatypes = {
    <span class="string">'.eot'</span>       : <span class="string">'application/vnd.ms-fontobject'</span>,
    <span class="string">'.gif'</span>       : <span class="string">'image/gif'</span>,
    <span class="string">'.ico'</span>       : <span class="string">'image/vnd.microsoft.icon'</span>,
    <span class="string">'.jpg'</span>       : <span class="string">'image/jpeg'</span>,
    <span class="string">'.jpeg'</span>      : <span class="string">'image/jpeg'</span>,
    <span class="string">'.otf'</span>       : <span class="string">'application/x-font-opentype'</span>,
    <span class="string">'.png'</span>       : <span class="string">'image/png'</span>,
    <span class="string">'.svg'</span>       : <span class="string">'image/svg+xml'</span>,
    <span class="string">'.ttf'</span>       : <span class="string">'application/x-font-ttf'</span>,
    <span class="string">'.webp'</span>      : <span class="string">'image/webp'</span>,
    <span class="string">'.woff'</span>      : <span class="string">'application/x-font-woff'</span>
}


<span class="function"><span class="keyword">function</span> <span class="title">converToBase64</span><span class="params">(imagePath)</span>{</span>
    imagePath = imagePath.replace(<span class="regexp">/[?#].*/g</span>, <span class="string">''</span>);
    <span class="keyword">var</span> extname = path.extname(imagePath),
        stat, img;
    <span class="keyword">try</span>{
        stat = fs.statSync(imagePath)
        <span class="keyword">if</span>(stat.size &gt; <span class="number">4096</span>){
            <span class="keyword">return</span> <span class="literal">false</span>
        }
        img = fs.readFileSync(imagePath, <span class="string">'base64'</span>);
        <span class="keyword">return</span> <span class="string">'data:'</span> + mediatypes[extname] + <span class="string">';base64,'</span> + img
    }<span class="keyword">catch</span>(e){
        <span class="keyword">return</span> <span class="literal">false</span>; 
    }
}</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
